package com.framework.modules.app.service.impl;

import com.framework.modules.base.entity.SimilarLocationUserListEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;

import com.framework.modules.app.dao.ViewUserOnlineListDao;
import com.framework.modules.app.entity.ViewUserOnlineListEntity;
import com.framework.modules.app.service.ViewUserOnlineListService;


@Service("viewUserOnlineListService")
public class ViewUserOnlineListServiceImpl extends ServiceImpl<ViewUserOnlineListDao, ViewUserOnlineListEntity> implements ViewUserOnlineListService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper wrapper=new EntityWrapper<ViewUserOnlineListEntity>();
        if(params.containsKey("uid")){
            wrapper.eq("uid",params.get("uid"));
        }
        if(params.containsKey("gender")){
            wrapper.eq("gender",params.get("gender"));
        }
        if(params.containsKey("is_online")){
            wrapper.eq("is_online",params.get("is_online"));
        }
        if(params.containsKey("tag")){
            String tag=params.get("tag").toString();
            List<String> tags=new ArrayList<>(Arrays.asList(tag.split(",")));
            if(tags.size()>0){
                wrapper.orNew();
            }
            for(String ta:tags) {
                wrapper.like("tags", ta);
            }
        }
        Page<ViewUserOnlineListEntity> page = this.selectPage(
                new Query<ViewUserOnlineListEntity>(params).getPage(),
                wrapper.orderBy("last_uptime",false)
        );

        return new PageUtils(page);
    }

    @Override
    public List<SimilarLocationUserListEntity> getSimilarSenceUserList(Map<String, Object> param) {
        return this.baseMapper.getSimilarSenceUserList(param);
    }

    @Override
    public List<SimilarLocationUserListEntity> getSimilarInterestUserList(Map<String, Object> param) {
        return this.baseMapper.getSimilarInterestUserList(param);
    }

    @Override
    public List<SimilarLocationUserListEntity> getSimilarLocationUserList(Map<String, Object> param) {
        return this.baseMapper.getSimilarLocationUserList(param);
    }

}
